package com.java.time;

import java.time.*;
import java.time.temporal.ChronoUnit;

public class Period_Duration_ChronoUnit_API {
    public static void main(String[] args) {
        Period period = Period.between(LocalDate.of(2001, 3, 4), LocalDate.of(2002, 5, 4));
        System.out.println(period.getYears()); // 1
        System.out.println(period.getMonths()); // 2
        System.out.println(period.getDays()); //0
        System.out.println(period.getUnits()); // [Years, Months, Days]
        System.out.println(period.toTotalMonths()); // 14
        
        Duration duration = Duration.between(LocalTime.of(0, 0, 0, 0), LocalTime.of(12, 12, 12, 12));
        System.out.println(duration.getSeconds()); // 43932
        System.out.println(duration.getNano()); // 12
        System.out.println(duration.getUnits()); // [Seconds, Nanos]
        System.out.println(duration.toDays()); // 0
        System.out.println(duration.toHours()); // 12
        System.out.println(duration.toMinutes()); // 732
        System.out.println(duration.toMillis()); // 43932000
        System.out.println(duration.toNanos()); // 43932000000012
        
        LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 0, 0, 0, 0);
        LocalDateTime localDateTime2 = LocalDateTime.of(2010, 10, 20, 21, 22, 23, 24);
        System.out.println(ChronoUnit.YEARS.between(localDateTime1, localDateTime2)); // 10
        System.out.println(ChronoUnit.DECADES.between(localDateTime1, localDateTime2)); // 1
        System.out.println(ChronoUnit.MONTHS.between(localDateTime1, localDateTime2)); // 129
        System.out.println(ChronoUnit.WEEKS.between(localDateTime1, localDateTime2)); // 563
        System.out.println(ChronoUnit.DAYS.between(localDateTime1, localDateTime2)); // 3945
        System.out.println(ChronoUnit.HALF_DAYS.between(localDateTime1, localDateTime2)); // 7891
        System.out.println(ChronoUnit.HOURS.between(localDateTime1, localDateTime2)); // 94701
        System.out.println(ChronoUnit.MINUTES.between(localDateTime1, localDateTime2)); // 5682082
        System.out.println(ChronoUnit.SECONDS.between(localDateTime1, localDateTime2)); // 340924943
        System.out.println(ChronoUnit.MILLIS.between(localDateTime1, localDateTime2)); // 340924943000
        System.out.println(ChronoUnit.MICROS.between(localDateTime1, localDateTime2)); // 340924943000000
        System.out.println(ChronoUnit.NANOS.between(localDateTime1, localDateTime2)); // 340924943000000024
    }
}
